package bbs;

import java.io.File;
import java.util.ArrayList;
import java.util.Hashtable;

import common.db.DBExecute;
import common.main.MainBean;

public class BbsFileUploadBean extends MainBean
{
	ArrayList uploadFileList;
	public BbsFileUploadBean(ArrayList uploadFileList)
	{
		this.uploadFileList = uploadFileList;
	}
	
	public void funcExecute() throws Exception
	{
		String id = (String)inputTable.get("id");
		String title = (String)inputTable.get("title");
		String content = (String)inputTable.get("content");
		String client = (String)inputTable.get("client");

		
		if(title.indexOf("'") != -1)
		{
			title = title.replaceAll("'", "''");
		}

		if(content.indexOf("'") != -1)
		{
			content = content.replaceAll("'", "''");
		}
		
		for(int i=0;i<uploadFileList.size();i++)
		{
			Hashtable uploadFileTable = (Hashtable)uploadFileList.get(i);
			String savePath =(String)uploadFileTable.get("savePath");
			String orgFileName =(String)uploadFileTable.get("orgFileName");
			String saveFileName =(String)uploadFileTable.get("saveFileName");
			File f = new File(savePath+"\\"+orgFileName);
			long fileSize = f.length();


			queryBuffer = new StringBuffer("");
			queryBuffer.append("INSERT INTO BBS_FILE (");
			queryBuffer.append("SEQ, BBS_SEQ, PATH, ORG_NAME, SAVE_NAME, FILE_SIZE, REG_ID, REG_IP, UPD_ID, UPD_IP");
			queryBuffer.append(") VALUES (");
			queryBuffer.append("BBS_FILE_SEQ.NEXTVAL, BBS_SEQ.NEXTVAL, '"+savePath+"', '"+orgFileName+"', ");
			queryBuffer.append("'"+saveFileName+"', '"+fileSize+"', '"+id+"', '"+client+"', '"+id+"', '"+client+"'");
			queryBuffer.append(")");
	
			DBExecute dbe = new DBExecute(queryBuffer.toString());
			outputList = dbe.getDataList();
		}
	}
}